import {
  Table,
  Row,
  Col,
  Form,
  Input,
  Icon,
  InputNumber,
  Radio,
  DatePicker,
  Select,
  Upload,
  Button,
  Switch,
  Modal,
  Popconfirm,
  Tabs,
  message,
  Steps,
  Card,
  Tag,
} from 'antd';

import { FormComponentProps } from 'antd/es/form';
import React from 'react';
import SingleDragger from '../../../../../components/Commons/SingleDragger';
import { connect } from 'dva';
import Constants from '@/utils/Constants';
import Validator from '@/utils/Validator';

const R = require('ramda');
const FormItem = Form.Item;
const RadioGroup = Radio.Group;

export default Form.create({ wrappedComponentRef: true })(
  class EditForm extends React.Component {
    constructor(props) {
      super(props);
      this.state = {
        open: false,
        disabled: '',
      };
    }

    componentDidMount() {
      if (R.equals(this.props.data.status)('1') || R.equals(this.props.data.status)('2')) {
        this.setState({ disabled: false });
      }
    }

    handleConfirm = () => {
      this.props.form.validateFields((errors, values) => {
        if (errors) return;

        // values.unapprovalfile = url;
        values.id = this.props.data.id;
        let props = this.props;

        this.props.dispatch({
          type: 'manageEnterpriseMyEnterprise/createCustomer',
          payload: {
            ...values,
            onSuccess: () => {
              props.dispatch({
                type: 'global/fetchUserInfo',
                payload: {},
              });
              this.props.refreshData();
            },
          },
        });
        values;
        this.handleCancel();
      });
    };

    handleOpen = () => {
      this.setState({ open: true });
    };

    handleCancel = () => {
      this.props.form.resetFields();
      this.setState({ open: false });
    };

    render() {
      const { getFieldDecorator } = this.props.form;
      let data = this.props.data;

      let disabledStatus = this.state.disabled;

      const formItemLayout = {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 7 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 12 },
          md: { span: 10 },
        },
      };

      let confirm = false ? (
        ''
      ) : (
        <Button
          style={{ marginLeft: 10 }}
          type="primary"
          size="small"
          onClick={() => {
            this.handleConfirm(true);
          }}
        >
          保存
        </Button>
      );
      let cancel = false ? (
        ''
      ) : (
        <Button
          style={{ marginLeft: 10 }}
          type="primary"
          size="small"
          onClick={() => {
            this.handleCancel(true);
          }}
        >
          返回
        </Button>
      );

      let footer = [];
      footer.push(
        <Button key="cancel" size="large" onClick={this.handleCancel.bind(this)}>
          取消
        </Button>,
      );
      footer.push(
        <Button key="submit" size="large" onClick={this.handleConfirm.bind(this, this.props)}>
          确认
        </Button>,
      );

      return (
        <Modal
          destroyOnClose
          title="新建企业"
          visible={this.state.open}
          width={900}
          footer={footer}
          onCancel={() => this.handleCancel.bind(this)()}
        >
          <Form style={{ marginTop: 8 }}>
            <Row gutter={24}>
              <Col span={8}>
                <FormItem label={<span>企业名称(中文)</span>}>
                  {getFieldDecorator('companyname', {
                    rules: [{ required: true, message: '请填写企业名称(中文)！' }],
                    initialValue: data.entepriseName,
                  })(<Input placeholder="填写姓名或昵称" />)}
                </FormItem>
              </Col>
              <Col span={8}>
                <FormItem label={<span>企业名称(英文)</span>}>
                  {getFieldDecorator('companynameen', {
                    rules: [{ required: true, message: '请填写企业名称(英文)！' }],
                    initialValue: data.entepriseNameEn,
                  })(<Input placeholder="填写姓名或昵称" />)}
                </FormItem>
              </Col>
              <Col span={8}>
                <FormItem label={<span>企业简称</span>}>
                  {getFieldDecorator('shortname', {
                    rules: [{ required: true, message: '请填写企业简称！' }],
                    initialValue: data.shortname,
                  })(<Input placeholder="填写姓名或昵称" />)}
                </FormItem>
              </Col>
              <Col span={8}>
                <FormItem label={<span>是否查询企业信用</span>}>
                  {getFieldDecorator('ischeckinfo', {
                    rules: [{ required: true, message: '请选择是否查询企业信用！' }],
                    initialValue: data.ischeckinfo,
                  })(
                    <RadioGroup>
                      <Radio value={'1'}>是</Radio>
                      <Radio value={'2'}>否</Radio>
                    </RadioGroup>,
                  )}
                </FormItem>
              </Col>
              <Col span={8}>
                <FormItem label={<span>企业类型</span>}>
                  {getFieldDecorator('companytype', {
                    rules: [{ required: true, message: '请选择企业类型！' }],
                    initialValue: data.companyType,
                  })(
                    <Select style={{ width: '100%' }}>
                      <Select.Option value="0" key="0">
                        一般纳税人
                      </Select.Option>
                      <Select.Option value="1" key="1">
                        小规模
                      </Select.Option>
                      <Select.Option value="2" key="2">
                        境外
                      </Select.Option>
                      <Select.Option value="3" key="3">
                        个人
                      </Select.Option>
                    </Select>,
                  )}
                </FormItem>
              </Col>
              <Col span={8}>
                <FormItem label={<span>经营模式</span>}>
                  {getFieldDecorator('businessmodel', {
                    rules: [{ required: true, message: '请选择经营模式！' }],
                    initialValue: data.businessmodel,
                  })(
                    <Select style={{ width: '100%' }}>
                      <Select.Option value={0} key={0}>
                        工贸一体
                      </Select.Option>
                      <Select.Option value={1} key={1}>
                        贸易型公司
                      </Select.Option>
                      <Select.Option value={2} key={2}>
                        生产型工厂
                      </Select.Option>
                    </Select>,
                  )}
                </FormItem>
              </Col>
              <Col span={8}>
                <FormItem label={<span>移动电话</span>}>
                  {getFieldDecorator('mobile', {
                    rules: [
                      { required: true, message: '请填写移动电话！' },
                      { pattern: Validator.mobile, message: '请输入正确的移动电话' },
                    ],
                    initialValue: data.mobile,
                  })(<Input placeholder="填写姓名或昵称" style={{ width: '100%' }} />)}
                </FormItem>
              </Col>
              <Col span={8}>
                <FormItem label={<span>固定电话</span>}>
                  {getFieldDecorator('telephone', {
                    rules: [
                      { required: true, message: '请填写固定电话！' },
                      { pattern: Validator.phone, message: '请输入正确的固定电话' },
                    ],
                    initialValue: data.telephone,
                  })(<Input placeholder="填写姓名或昵称" style={{ width: '100%' }} />)}
                </FormItem>
              </Col>
              <Col span={8}>
                <FormItem label={<span>邮箱（E-mail）</span>}>
                  {getFieldDecorator('email', {
                    rules: [
                      { required: true, message: '请填写邮箱（E-mail）！' },
                      { type: 'email', message: '请填写正确的邮箱' },
                    ],
                    initialValue: data.email,
                  })(<Input placeholder="填写姓名或昵称" />)}
                </FormItem>
              </Col>
              <Col span={8}>
                <FormItem label={<span>传真</span>}>
                  {getFieldDecorator('tax', {
                    rules: [{ required: false, message: '请填写传真！' }],
                    initialValue: data.tax,
                  })(<Input placeholder="填写姓名或昵称" />)}
                </FormItem>
              </Col>
              <Col span={8}>
                <FormItem label={<span>统一信用代码</span>}>
                  {getFieldDecorator('taxpayerid', {
                    rules: [{ required: true, message: '请填写统一信用代码！' }],
                    initialValue: data.taxpayerid,
                  })(<Input placeholder="填写统一信用代码" />)}
                </FormItem>
              </Col>
              <Col span={8}>
                <FormItem label={<span>海关注册登记号码</span>}>
                  {getFieldDecorator('customsregno', {
                    rules: [{ required: true, message: '请填写海关注册登记号码！' }],
                    initialValue: data.customsregno,
                  })(<Input placeholder="填写姓名或昵称" />)}
                </FormItem>
              </Col>
              <Col span={8}>
                <FormItem label={<span>公司地址(中文)</span>}>
                  {getFieldDecorator('address', {
                    rules: [{ required: true, message: '请填写公司地址(中文)！' }],
                    initialValue: data.address,
                  })(<Input placeholder="填写姓名或昵称" />)}
                </FormItem>
              </Col>
              <Col span={8}>
                <FormItem label={<span>公司地址(英文)</span>}>
                  {getFieldDecorator('addressen', {
                    rules: [{ required: true, message: '请填写公司地址(英文)！' }],
                    initialValue: data.addressen,
                  })(<Input placeholder="填写姓名或昵称" />)}
                </FormItem>
              </Col>
              <Col span={8}>
                <FormItem label={<span>收件地址</span>}>
                  {getFieldDecorator('recaddress', {
                    rules: [{ required: true, message: '请填写收件地址！' }],
                    initialValue: data.recaddress,
                  })(<Input placeholder="填写姓名或昵称" />)}
                </FormItem>
              </Col>
              <Col span={8}>
                <FormItem label={<span>公司网址</span>}>
                  {getFieldDecorator('url', {
                    rules: [{ required: false, message: '请填写公司网址！' }],
                    initialValue: data.url,
                  })(<Input placeholder="填写姓名或昵称" />)}
                </FormItem>
              </Col>
            </Row>
            {/*<Row>*/}
            {/*<Col span={12}>*/}
            {/*<FormItem {...formItemLayout} label="附件(待审核单证)" hasFeedback>*/}
            {/*<SingleDragger ref="unapprovalfile" url={''} dataSource={''} module={"qianzhuang"}/>*/}
            {/*</FormItem>*/}
            {/*</Col>*/}
            {/*</Row>*/}
          </Form>
        </Modal>
      );
    }
  },
);
// export default connect(({ global, loading }) => ({ global, loading }))(SingleDragger);
